package edu.thu.studio.ormdesigner.editor.editpart;

import org.eclipse.draw2d.IFigure;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ui.PlatformUI;

import edu.thu.studio.ormdesigner.editor.dialog.ViewDialog;
import edu.thu.studio.ormdesigner.editor.figure.ViewFigure;
import edu.thu.studio.ormdesigner.model.diagram.node.ViewNode;
import edu.thu.studio.ormdesigner.model.orm.view.View;
import edu.thu.studio.ormdesigner.outline.command.UpdateViewCommand;

public class ViewNodeEditPart extends NodeEditPart {
    
    @Override
    protected IFigure createFigure() {
        ViewFigure figure = new ViewFigure();
        return figure;
    }
    
    @Override
    public void performRequestOpen() {
        View view = (View) ((ViewNode)this.getModel()).getRefTable();
        ViewDialog dialog = new ViewDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            this.getViewer(), view);
        if (dialog.open() == IDialogConstants.OK_ID) {
            UpdateViewCommand command = new UpdateViewCommand(view);
            this.executeCommand(command);
        }
    }
    
}
